package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.system.domain.SysHome;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.mapper.SysHomeMapper;
import com.ruoyi.system.service.SysHomeService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 首页信息维护Service业务层处理
 * 
 * @author xx
 * @date 2020-04-16
 */
@Service
public class SysHomeServiceImpl implements SysHomeService {
    @Autowired
    private SysHomeMapper sysHomeMapper;

    /**
     * 查询首页信息维护
     * 
     * @param id 首页信息维护ID
     * @return 首页信息维护
     */
    @Override
    public SysHome selectSysHomeById(Long id) {
        return sysHomeMapper.selectSysHomeById(id);
    }

    /**
     * 查询首页信息维护列表
     * 
     * @param sysHome 首页信息维护
     * @return 首页信息维护
     */
    @Override
    public List<SysHome> selectSysHomeList(SysHome sysHome) {
        return sysHomeMapper.selectSysHomeList(sysHome);
    }

    /**
     * 新增首页信息维护
     * 
     * @param sysHome 首页信息维护
     * @return 结果
     */
    @Override
    public int insertSysHome(SysHome sysHome) {
        SysUser user = BeanUtils.copyBean(SecurityUtils.getSubject().getPrincipal(), SysUser.class);
        sysHome.setCreateBy(user.getLoginName());
        sysHome.setCreateTime(DateUtils.getNowDate());
        return sysHomeMapper.insertSysHome(sysHome);
    }

    /**
     * 修改首页信息维护
     * 
     * @param sysHome 首页信息维护
     * @return 结果
     */
    @Override
    public int updateSysHome(SysHome sysHome) {
        SysUser user = BeanUtils.copyBean(SecurityUtils.getSubject().getPrincipal(), SysUser.class);
        sysHome.setUpdateBy(user.getLoginName());
        sysHome.setUpdateTime(DateUtils.getNowDate());
        return sysHomeMapper.updateSysHome(sysHome);
    }

    /**
     * 删除首页信息维护对象
     * 
     * @param sysHome 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteSysHomeByIds(SysHome sysHome) {
        SysUser user = BeanUtils.copyBean(SecurityUtils.getSubject().getPrincipal(), SysUser.class);
        sysHome.setUpdateBy(user.getLoginName());
        return sysHomeMapper.deleteSysHomeByIds(sysHome);
    }

    /**
     * 删除首页信息维护信息
     * 
     * @param id 首页信息维护ID
     * @return 结果
     */
    @Override
    public int deleteSysHomeById(Long id) {
        return sysHomeMapper.deleteSysHomeById(id);
    }

    @Override
    public int changeStatus(SysHome sysHome) {
        SysUser user = BeanUtils.copyBean(SecurityUtils.getSubject().getPrincipal(), SysUser.class);
        sysHome.setUpdateBy(user.getLoginName());
        return sysHomeMapper.changeStatus(sysHome);
    }
}
